<template>
    <div id="dd">
        <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="账号" prop="userss">
                <el-input type="text" v-model="ruleForm.userss" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="checkPass">
                <el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
                <el-button @click="resetForm('ruleForm')">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
  export default {
    data() {
       var validatePass = (rule, value, callback) => {
         if (value === '') {
           callback(new Error('请输入账号'));
         } else {
           callback();
         }
       };
        var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        }  else {
          callback();
        }
      };
      return {
        ruleForm: {
          userss: '',
          checkPass: ''
        },
        rules: {
           userss: [
             { validator: validatePass, trigger: 'blur' }
           ],
           checkPass: [
            { validator: validatePass2, trigger: 'blur' }
          ],
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
                        sessionStorage.setItem("user",this.ruleForm.userss)
                        sessionStorage.setItem("pwd",this.ruleForm.checkPass)
                        this.$store.commit("getUsers")
                        this.$router.push("/")
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>